package com.py.net.server.businese;

import com.google.protobuf.MessageLite;
import com.py.net.proto.ChatProbuf.CTSChat;
import com.py.net.proto.ChatProbuf.STCChat;
import com.py.net.proto.ChatProbuf.STCChatRet;
import com.py.net.proto.IBusineseHandle;
import com.py.net.server.Server;

public class ServerChatHandle extends IBusineseHandle<CTSChat> {

	@Override
	public MessageLite handle(CTSChat msg) {
		STCChatRet.Builder builder = STCChatRet.newBuilder();
		if (session.user == null) {
			//未登录
			builder.setStatus(1);
			builder.setMsg("请先登陆");
		} else {
			builder.setStatus(0);
			builder.setMsg("发送成功");
			//发送给聊天室所有成员
			Server.broadcast(STCChat.newBuilder().setSendId(session.user.id).setSendName(session.user.name).setMsg(msg.getMsg()).build());
		}
		return builder.build();
	}

}
